package com.kmproject.haifu.mvp.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HFLocationBean;
import com.kmproject.haifu.mvp.ui.activity.HouseRentShowInfoActivity;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

public class HouseRentingHeZuShowListAdapter extends BaseQuickAdapter<HouseRentListShowBean,BaseViewHolder> {

    ImageLoader glideImage;
    private HFLocationBean mbdLocation;
    public HouseRentingHeZuShowListAdapter( @Nullable List<HouseRentListShowBean> data) {
        super(R.layout.house_renting_show_hezu_item, data);

    }


    public void setMbdLocation(HFLocationBean mbdLocation) {
        this.mbdLocation = mbdLocation;
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseRentListShowBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv3).setText(item.getHouseName()+"."+item.getRentRoomName());
        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv6).setText(item.getAddressDetail());
        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv4).setText(item.getFormatMonthRent());

        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView1).setLayoutManager(new GridLayoutManager(mContext, 3));
        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView1).addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(2)));
        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView1).setAdapter(new HouseRentingShowHeZuImgtemAdapter(item.getHouseImageList()));

        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView2).setLayoutManager(new GridLayoutManager(mContext, 3));
        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView2).addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(2)));
        helper.<RecyclerView>getView(R.id.houseRentingShow_hezu_item_RecyclerView2).setAdapter(new HouseRentingShowHeZuYqItemAdapter(item.getDetails()));
        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv7).setText((item.getUpdDiffDay()>0?item.getUpdDiffDay()+"天":(item.getUpdDiffHour()>0?item.getUpdDiffHour()+"小时":item.getUpdDiffMinute()+"分钟"))+"前."+item.getViewCount()+"浏览");


        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv1).setText(item.getLandlord());
        helper.<TextView>getView(R.id.houseRentingShow_hezu_item_tv2).setText("来海服"+(item.getLogDiffDay()>0?item.getLogDiffDay()+"天":(item.getLogDiffHour()>0?item.getLogDiffHour()+"小时":item.getLogDiffMinute()+"分钟"))+", "+item.getLandlordGender());
            if (item.getAvatar()!=null&&!TextUtils.isEmpty(item.getAvatar()))
            {
                glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getAvatar()).imageRadius(5)
                        .imageView(helper.<ImageView>getView(R.id.houseRentingShow_hezu_item_header_img))
                        .build());
            }
            helper.getView(R.id.houseRentingShow_hezu_item_lay).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext,HouseRentShowInfoActivity.class);
                    intent.putExtra("rentId",item.getRentId());
                    if (mbdLocation!=null)
                    {
                        intent.putExtra("lgt",mbdLocation.getMlocation().getLongitude()+"");
                        intent.putExtra("lat",mbdLocation.getMlocation().getLatitude()+"");
                    }else {
                        intent.putExtra("lgt","0");
                        intent.putExtra("lat","0");
                    }
                    ArmsUtils.startActivity(intent);
                }
            });
    }
}
